SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

/****** Object:  Table [dbo].[Persons]    Script Date: 07/02/2011 20:29:31 ******/

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[PersonsSelectByPersonID]') and type in (N'P', N'PC'))
DROP PROCEDURE PersonsSelectByPersonID
GO
 
CREATE PROCEDURE PersonsSelectByPersonID
     @personID        int
AS
BEGIN
	SELECT * FROM [dbo].[Persons]
	 WHERE [PersonID] = @personID
END
GO


IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[PersonsInsert]') and type in (N'P', N'PC'))
    DROP PROCEDURE PersonsInsert
GO
 
CREATE PROCEDURE PersonsInsert
     @title        nvarchar(5)
    ,@firstName    nvarchar(50)
    ,@lastName     nvarchar(50)
    ,@entryDate    datetime
    ,@identity     int out
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
 
    INSERT INTO [dbo].[Persons] (
             [Title]
            ,[FirstName]
            ,[LastName]
            ,[EntryDate]
            )
        SELECT 
            @title     
            ,@firstName
            ,@lastName
            ,@entryDate
 
    SET @number_of_rows_affected = @@ROWCOUNT
    SET @identity = @@IDENTITY
    SET @error = @@error
    IF @error<>0 
    BEGIN 
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Insert into Persons failed',16, 1, @proc_error)
    END
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[PersonsUpdate]') and type in (N'P', N'PC'))
    DROP PROCEDURE PersonsUpdate
GO
 
CREATE PROCEDURE PersonsUpdate
     @personID        bigint
    ,@title        nvarchar(5)
    ,@firstName    nvarchar(50)
    ,@lastName     nvarchar(50)
    ,@entryDate    datetime
    
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
    DECLARE @dateval datetime
 
    set @dateval = getdate()
 
    UPDATE [dbo].[Persons]
       SET 
         [Title]      = @title     
        ,[FirstName]  = @firstName   
        ,[LastName]   = @lastName
        ,[EntryDate]  = @entryDate
        ,[ModifyDate] = getdate()
     WHERE [PersonID] = @personID
 
    set @number_of_rows_affected = @@ROWCOUNT
    set @error = @@error
    If @error<>0 
    BEGIN
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Update of Persons failed',16, 1, @proc_error)
    END
    If @number_of_rows_affected = 0 
    BEGIN
        select @proc_error = 'Error: Persons Primary Key [PersonID] value is not valid: ' + @personID
        RAISERROR ('No rows updated %s', 16, 1, @proc_error) 
    END
END 

GO


/****** Object:  Table [dbo].[Address]    Script Date: 07/02/2011 20:30:04 ******/

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[AddressSelectByAddressID]') and type in (N'P', N'PC'))
DROP PROCEDURE AddressSelectByAddressID
GO
 
CREATE PROCEDURE AddressSelectByAddressID
     @addressID        int
    ,@personID         int
AS
BEGIN
	SELECT * FROM [dbo].[Address]
	 WHERE [AddressID] = @addressID OR [PersonID] = @personID
END
GO


IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[AddressInsert]') and type in (N'P', N'PC'))
    DROP PROCEDURE AddressInsert
GO
 
CREATE PROCEDURE AddressInsert
	 @personID        int
    ,@addressLine1    nvarchar(40)
    ,@addressLine2    nvarchar(30)
    ,@addressLine3    nvarchar(30)
    ,@addressLine4    nvarchar(30)
    ,@postalCode      nvarchar(30)
    ,@country         nvarchar(50)
    ,@phoneNumber     nvarchar(50)
    ,@email           nvarchar(100)
    ,@identity        int out
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
 
    INSERT INTO [dbo].[Address] (
            [PersonID]
            ,[AddressLine1]
            ,[AddressLine2]
            ,[AddressLine3]
            ,[AddressLine4]
            ,[PostalCode]
            ,[Country]
            ,[PhoneNumber]
            ,[Email]
            )
        SELECT 
             @personID     
            ,@addressLine1
            ,@addressLine2 
            ,@addressLine3 
            ,@addressLine4 
            ,@postalCode   
			,@country      
            ,@phoneNumber
            ,@email 
            
    SET @number_of_rows_affected = @@ROWCOUNT
    SET @identity = @@IDENTITY
    SET @error = @@error
    IF @error<>0 
    BEGIN 
        SELECT @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description FROM master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Insert into Address failed',16, 1, @proc_error)
    END
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[AddressUpdate]') and type in (N'P', N'PC'))
    DROP PROCEDURE AddressUpdate
GO
 
CREATE PROCEDURE AddressUpdate
     @addressID       int
	,@personID        int
    ,@addressLine1    nvarchar(40)
    ,@addressLine2    nvarchar(30)
    ,@addressLine3    nvarchar(30)
    ,@addressLine4    nvarchar(30)
    ,@postalCode      nvarchar(30)
    ,@country         nvarchar(50)
    ,@phoneNumber     nvarchar(50)
    ,@email           nvarchar(100)
    
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
    DECLARE @dateval datetime
 
    UPDATE [dbo].[Address]
       SET 
        [AddressLine1]    = @addressLine1   
        ,[AddressLine2]   = @addressLine2   
        ,[AddressLine3]	  =	@addressLine3   
        ,[AddressLine4]	  =	@addressLine4   
        ,[PostalCode]	  = @postalCode     
        ,[Country]		  =	@country        
        ,[PhoneNumber]	  =	@phoneNumber        
        ,[Email]	      =	@email    
        ,[ModifyDate]     = getdate()
     WHERE [AddressID] = @addressID OR [PersonID] = @personID
 
    set @number_of_rows_affected = @@ROWCOUNT
    set @error = @@error
    If @error<>0 
    BEGIN
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Update of Address failed',16, 1, @proc_error)
    END
    If @number_of_rows_affected = 0 
    BEGIN
        select @proc_error = 'Error: Address Primary Key [AddressID] value is not valid: ' + @addressID
        RAISERROR ('No rows updated %s', 16, 1, @proc_error) 
    END
END 
GO



/****** Object:  Table [dbo].[PersonsExpired]    Script Date: 07/02/2011 20:29:31 ******/

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[PersonExpiredSelectByPersonExpiredID]') and type in (N'P', N'PC'))
DROP PROCEDURE PersonExpiredSelectByPersonExpiredID
GO
 
CREATE PROCEDURE PersonExpiredSelectByPersonExpiredID
     @personExpiredID        int
    ,@personID               int
AS
BEGIN
	SELECT * FROM [dbo].[PersonsExpired]
	 WHERE [PersonExpiredID] = @personExpiredID OR [PersonID] = @personID
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[PersonsExpiredInsert]') and type in (N'P', N'PC'))
    DROP PROCEDURE PersonsExpiredInsert
GO
 
CREATE PROCEDURE PersonsExpiredInsert
	 @personID        int
    ,@enable          bit
    ,@expired         datetime
    ,@identity        int out
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
 
    INSERT INTO [dbo].[PersonsExpired] (
            [PersonID]
            ,[Enable]
            ,[Expired]
            )
        SELECT 
             @personID     
            ,@enable
            ,@identity 
            
    SET @number_of_rows_affected = @@ROWCOUNT
    SET @identity = @@IDENTITY
    SET @error = @@error
    IF @error<>0 
    BEGIN 
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Insert into PersonsExpired failed',16, 1, @proc_error)
    END
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[PersonsExpiredUpdate]') and type in (N'P', N'PC'))
    DROP PROCEDURE PersonsExpiredUpdate
GO
 
CREATE PROCEDURE PersonsExpiredUpdate
     @personExpiredID int
	,@personID        int
    ,@enable          bit
    ,@expired         datetime
    
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
    DECLARE @dateval datetime
 
    UPDATE [dbo].[PersonsExpired]
       SET 
        [Enable]    = @enable   
        ,[Expired]   = @expired   
        ,[PersonID]	  =	@personID
        ,[ModifyDate]     = getdate()
     WHERE [PersonExpiredID] = @personExpiredID
 
    set @number_of_rows_affected = @@ROWCOUNT
    set @error = @@error
    If @error<>0 
    BEGIN
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Update of PersonExpired failed',16, 1, @proc_error)
    END
    If @number_of_rows_affected = 0 
    BEGIN
        select @proc_error = 'Error: PersonExpired Primary Key [PersonExpiredID] value is not valid: ' + @personExpiredID
        RAISERROR ('No rows updated %s', 16, 1, @proc_error) 
    END
END 
GO



/****** Object:  Table [dbo].[TransactionModes]    Script Date: 07/02/2011 20:34:53 ******/

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[TransactionModesSelectByTransactionModeID]') and type in (N'P', N'PC'))
DROP PROCEDURE TransactionModesSelectByTransactionModeID
GO
 
CREATE PROCEDURE TransactionModesSelectByTransactionModeID
     @transactionModeID        int
AS
BEGIN
	SELECT * FROM [dbo].[TransactionModes]
	 WHERE [TransactionModeID] = @transactionModeID
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[TransactionModesInsert]') and type in (N'P', N'PC'))
    DROP PROCEDURE TransactionModesInsert
GO
 
CREATE PROCEDURE TransactionModesInsert
     @transactionModeName    nvarchar(40)
    ,@identity        int out
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
 
    INSERT INTO [dbo].[TransactionModes] (
            [TransactionModeName]
            )
        SELECT 
             @transactionModeName 
            
    SET @number_of_rows_affected = @@ROWCOUNT
    SET @identity = @@IDENTITY
    SET @error = @@error
    IF @error<>0 
    BEGIN 
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Insert into TransactionModes failed',16, 1, @proc_error)
    END
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[TransactionModesUpdate]') and type in (N'P', N'PC'))
    DROP PROCEDURE TransactionModesUpdate
GO
 
CREATE PROCEDURE TransactionModesUpdate
	 @transactionModeID      int
     ,@transactionModeName    nvarchar(40)
    
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
    DECLARE @dateval datetime
 
    UPDATE [dbo].[TransactionModes]
       SET 
        [TransactionModeName]    = @transactionModeName
        ,[ModifyDate]     = getdate()
     WHERE [TransactionModeID] = @transactionModeID
 
    set @number_of_rows_affected = @@ROWCOUNT
    set @error = @@error
    If @error<>0 
    BEGIN
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Update of TransactionModes failed',16, 1, @proc_error)
    END
    If @number_of_rows_affected = 0 
    BEGIN
        select @proc_error = 'Error: TransactionModes Primary Key [TransactionModesID] value is not valid: ' + @transactionModeID
        RAISERROR ('No rows updated %s', 16, 1, @proc_error) 
    END
END 
GO


/****** Object:  Table [dbo].[PostalModes]    Script Date: 07/02/2011 20:35:28 ******/

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[PostalModesSelectByPostalModeID]') and type in (N'P', N'PC'))
DROP PROCEDURE PostalModesSelectByPostalModeID
GO
 
CREATE PROCEDURE PostalModesSelectByPostalModeID
     @postalModeID        int
AS
BEGIN
    IF @postalModeID = 0 
		BEGIN
			SELECT * FROM [dbo].[PostalModes]
		END
    ELSE
		BEGIN
			SELECT * FROM [dbo].[PostalModes]
			 WHERE [PostalModeID] = @postalModeID
		END
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[PostalModesInsert]') and type in (N'P', N'PC'))
    DROP PROCEDURE PostalModesInsert
GO
 
CREATE PROCEDURE PostalModesInsert
     @postalModesName    nvarchar(40)
    ,@identity        int out
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
 
    INSERT INTO [dbo].[PostalModes] (
            [PostalModeName]
            )
        SELECT 
             @postalModesName 
            
    SET @number_of_rows_affected = @@ROWCOUNT
    SET @identity = @@IDENTITY
    SET @error = @@error
    IF @error<>0 
    BEGIN 
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Insert into PostalModes failed',16, 1, @proc_error)
    END
END
GO



/****** Object:  Table [dbo].[DonationPlace]    Script Date: 07/02/2011 20:34:16 ******/

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[DonationPlaceSelectByDonationPlaceID]') and type in (N'P', N'PC'))
DROP PROCEDURE DonationPlaceSelectByDonationPlaceID
GO
 
CREATE PROCEDURE DonationPlaceSelectByDonationPlaceID
     @donationPlaceID        int
AS
BEGIN
	SELECT * FROM [dbo].[DonationPlace]
	 WHERE [DonationPlaceID] = @donationPlaceID
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[DonationPlaceInsert]') and type in (N'P', N'PC'))
    DROP PROCEDURE DonationPlaceInsert
GO
 
CREATE PROCEDURE DonationPlaceInsert
     @donationPlaceName    nvarchar(40)
    ,@enable          bit
    ,@identity        int out
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
 
    INSERT INTO [dbo].[DonationPlace] (
            [DonationPlaceName]
            ,[Enable]
            )
        SELECT 
             @donationPlaceName 
            ,@enable
            
    SET @number_of_rows_affected = @@ROWCOUNT
    SET @identity = @@IDENTITY
    SET @error = @@error
    IF @error<>0 
    BEGIN 
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Insert into DonationPlace failed',16, 1, @proc_error)
    END
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[DonationPlaceUpdate]') and type in (N'P', N'PC'))
    DROP PROCEDURE DonationPlaceUpdate
GO
 
CREATE PROCEDURE DonationPlaceUpdate
	 @donationPlaceID      int
    ,@donationPlaceName    nvarchar(40)
    ,@enable               bit
    
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
    DECLARE @dateval datetime
 
    UPDATE [dbo].[DonationPlace]
       SET 
        [DonationPlaceName] = @donationPlaceName
        ,[Enable]           = @enable
        ,[ModifyDate]       = getdate()
     WHERE [DonationPlaceID] = @donationPlaceID
 
    set @number_of_rows_affected = @@ROWCOUNT
    set @error = @@error
    If @error<>0 
    BEGIN
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Update of DonationPlace failed',16, 1, @proc_error)
    END
    If @number_of_rows_affected = 0 
    BEGIN
        select @proc_error = 'Error: DonationPlace Primary Key [DonationPlaceID] value is not valid: ' + @donationPlaceID
        RAISERROR ('No rows updated %s', 16, 1, @proc_error) 
    END
END 
GO




/****** Object:  Table [dbo].[DonationAccounts]    Script Date: 07/02/2011 20:34:16 ******/

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[DonationAccountsSelectByDonationAccountID]') and type in (N'P', N'PC'))
DROP PROCEDURE DonationAccountsSelectByDonationAccountID
GO
 
CREATE PROCEDURE DonationAccountsSelectByDonationAccountID
     @donationAccountID        int
AS
BEGIN
    IF @donationAccountID = 0 
		BEGIN
			SELECT * FROM [dbo].[DonationAccounts]
		END
    ELSE
		BEGIN
			SELECT * FROM [dbo].[DonationAccounts]
			 WHERE [DonationAccountID] = @donationAccountID
		END
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[DonationAccountsInsert]') and type in (N'P', N'PC'))
    DROP PROCEDURE DonationAccountsInsert
GO
 
CREATE PROCEDURE DonationAccountsInsert
     @donationPlaceID        int
    ,@donationAccountName    nvarchar(40)
    ,@enable                 bit
    ,@identity               int out
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
 
    INSERT INTO [dbo].[DonationAccounts] (
             [DonationPlaceID]
            ,[DonationAccountName]
            ,[Enable]
            )
        SELECT 
              @donationPlaceID
             ,@donationAccountName 
             ,@enable
            
    SET @number_of_rows_affected = @@ROWCOUNT
    SET @identity = @@IDENTITY
    SET @error = @@error
    IF @error<>0 
    BEGIN 
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Insert into DonationAccounts failed',16, 1, @proc_error)
    END
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[DonationAccountsUpdate]') and type in (N'P', N'PC'))
    DROP PROCEDURE DonationAccountsUpdate
GO
 
CREATE PROCEDURE DonationAccountsUpdate
	 @donationAccountID      int
	,@donationPlaceID        int
    ,@donationAccountName    nvarchar(40)
    ,@enable                 bit
    
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
    DECLARE @dateval datetime
 
    UPDATE [dbo].[DonationAccounts]
       SET 
         [DonationAccountName] = @donationAccountName
        ,[DonationPlaceID] = @donationPlaceID
        ,[Enable]           = @enable
        ,[ModifyDate]       = getdate()
     WHERE [DonationAccountID] = @donationAccountID
 
    set @number_of_rows_affected = @@ROWCOUNT
    set @error = @@error
    If @error<>0 
    BEGIN
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Update of DonationAccount failed',16, 1, @proc_error)
    END
    If @number_of_rows_affected = 0 
    BEGIN
        select @proc_error = 'Error: DonationAccount Primary Key [DonationAccountID] value is not valid: ' + @donationAccountID
        RAISERROR ('No rows updated %s', 16, 1, @proc_error) 
    END
END 
GO


/****** Object:  Table [dbo].[Transactions]    Script Date: 07/02/2011 20:34:16 ******/

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[TransactionsSelectByTransactionID]') and type in (N'P', N'PC'))
DROP PROCEDURE TransactionsSelectByTransactionID
GO
 
CREATE PROCEDURE TransactionsSelectByTransactionID
     @transactionID        int
AS
BEGIN
	SELECT * FROM [dbo].[Transactions]
	 WHERE [TransactionID] = @transactionID
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[TransactionsInsert]') and type in (N'P', N'PC'))
    DROP PROCEDURE TransactionsInsert
GO
 
CREATE PROCEDURE TransactionsInsert
     @transactionModeID        int
    ,@personID                 int
    ,@transactionModeNumber    nvarchar(50)
    ,@transactionModeDate      datetime
    ,@transactionAmount        decimal(19,2)
    ,@transactionModeBank      nvarchar(50)
    ,@transactionDate          datetime
    ,@identity                 int out
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
 
    INSERT INTO [dbo].[Transactions] (
              [PersonID]
             ,[TransactionModeID]     
			 ,[TransactionModeNumber] 
			 ,[TransactionModeDate]   
			 ,[TransactionAmount]     
             ,[TransactionModeBank]   
             ,[TransactionDate]
             )       
        SELECT 
              @personID
             ,@transactionModeID     
             ,@transactionModeNumber 
             ,@transactionModeDate   
             ,@transactionAmount     
             ,@transactionModeBank   
             ,@transactionDate 
            
    SET @number_of_rows_affected = @@ROWCOUNT
    SET @identity = @@IDENTITY
    SET @error = @@error
    IF @error<>0 
    BEGIN 
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Insert into Transactions failed',16, 1, @proc_error)
    END
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[TransactionsUpdate]') and type in (N'P', N'PC'))
    DROP PROCEDURE TransactionsUpdate
GO
 
CREATE PROCEDURE TransactionsUpdate
     @transactionID            int
    ,@personID                 int
    ,@transactionModeID        int
    ,@transactionModeNumber    nvarchar(50)
    ,@transactionModeDate      datetime
    ,@transactionAmount        decimal(19,2)
    ,@transactionModeBank      nvarchar(50)
    ,@transactionDate          datetime
    
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
    DECLARE @dateval datetime
 
    UPDATE [dbo].[Transactions]
       SET 
         [TransactionModeID]     = @transactionModeID      
        ,[TransactionModeNumber] = @transactionModeNumber  
        ,[TransactionModeDate]   = @transactionModeDate    
        ,[TransactionAmount]     = @transactionAmount      
        ,[TransactionModeBank]   = @transactionModeBank    
        ,[TransactionDate]       = @transactionDate      
        ,[ModifyDate]            = getdate()
     WHERE [TransactionID] = @transactionID OR [PersonID] = @personID
 
    set @number_of_rows_affected = @@ROWCOUNT
    set @error = @@error
    If @error<>0 
    BEGIN
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Update of Transactions failed',16, 1, @proc_error)
    END
    If @number_of_rows_affected = 0 
    BEGIN
        select @proc_error = 'Error: Transactions Primary Key [TransactionID] value is not valid: ' + @transactionID
        RAISERROR ('No rows updated %s', 16, 1, @proc_error) 
    END
END 
GO




/****** Object:  Table [dbo].[TransactionReceiptDetail]    Script Date: 07/02/2011 20:34:16 ******/

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[TransactionReceiptDetailSelectByTransactionReceiptDetailID]') and type in (N'P', N'PC'))
DROP PROCEDURE TransactionReceiptDetailSelectByTransactionReceiptDetailID
GO
 
CREATE PROCEDURE TransactionReceiptDetailSelectByTransactionReceiptDetailID
     @transactionReceiptDetailID        int
AS
BEGIN
	SELECT * FROM [dbo].[TransactionReceiptDetail]
	 WHERE [TransactionReceiptDetailID] = @transactionReceiptDetailID
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[TransactionReceiptDetailInsert]') and type in (N'P', N'PC'))
    DROP PROCEDURE TransactionReceiptDetailInsert
GO
 
CREATE PROCEDURE TransactionReceiptDetailInsert
     @transactionID              int
    ,@DonationAccountID          int
    ,@transactionReceiptNumber   nvarchar(19)
    ,@transactionReceiptDate     datetime
    ,@postalModeID               int
    ,@despatchDate               datetime
    ,@identity                   int out
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
 
    INSERT INTO [dbo].[TransactionReceiptDetail] (
              [TransactionID]            
			 ,[DonationAccountID]         
			 ,[TransactionReceiptNumber]  
			 ,[TransactionReceiptDate] 
			 ,[PostalModeID]
             ,[DespatchDate]              
             
             )       
        SELECT 
              @transactionID           
             ,@DonationAccountID       
             ,@transactionReceiptNumber 
             ,@transactionReceiptDate  
             ,@postalModeID
             ,@despatchDate            
            
    SET @number_of_rows_affected = @@ROWCOUNT
    SET @identity = @@IDENTITY
    SET @error = @@error
    IF @error<>0 
    BEGIN 
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Insert into TransactionReceiptDetail failed',16, 1, @proc_error)
    END
END
GO

IF EXISTS (select * from sys.objects where object_id = object_id(N'[dbo].[TransactionReceiptDetailUpdate]') and type in (N'P', N'PC'))
    DROP PROCEDURE TransactionReceiptDetailUpdate
GO
 
CREATE PROCEDURE TransactionReceiptDetailUpdate
     @transactionReceiptDetailID  int
    ,@transactionID               int
    ,@donationAccountID           int
    ,@transactionReceiptNumber    nvarchar(19)
    ,@transactionReceiptDate      datetime
    ,@postalModeID                int
    ,@despatchDate                datetime
    
AS
BEGIN
    DECLARE @error int
    DECLARE @number_of_rows_affected int
    DECLARE @proc_error varchar (250)
    DECLARE @dateval datetime
 
    UPDATE [dbo].[TransactionReceiptDetail]
       SET 
         [donationAccountID]        = @DonationAccountID         
        ,[TransactionReceiptNumber] = @transactionReceiptNumber  
        ,[TransactionReceiptDate]   = @transactionReceiptDate 
        ,[PostalModeID]             = @postalModeID
        ,[DespatchDate]             = @despatchDate 
        ,[ModifyDate]               = getdate()
     WHERE [TransactionReceiptDetailID] = @transactionReceiptDetailID OR [TransactionID] = @transactionID
 
    set @number_of_rows_affected = @@ROWCOUNT
    set @error = @@error
    If @error<>0 
    BEGIN
        select @proc_error = 'Error: ' + convert(varchar(20),@error)+ '. '+ description from master..sysmessages
            WHERE error = @error and  msglangid = 1033
        RAISERROR ('Update of TransactionReceiptDetail failed',16, 1, @proc_error)
    END
    If @number_of_rows_affected = 0 
    BEGIN
        select @proc_error = 'Error: TransactionReceiptDetail Primary Key [TransactionReceiptDetailID] value is not valid: ' + @transactionReceiptDetailID
        RAISERROR ('No rows updated %s', 16, 1, @proc_error) 
    END
END 
GO




